﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AjaxControlToolkit;
using System.Collections.Specialized;
using Icst.Leaflike.Data;
using System.Web.Script.Services;

namespace Icst.Leaflike.Web.category
{
    [WebService(Namespace = "http://www.icst.com.cn/leaflike")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class categories : System.Web.Services.WebService
    {
        [WebMethod]
        public CascadingDropDownNameValue[] Getphylums(string knownCategoryValues, string category)
        {
            List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
            foreach (var dr in Category.Instance.Getphylums())
            {
                values.Add(new CascadingDropDownNameValue(dr, dr));
            }
            return values.ToArray();
        }

        [WebMethod]
        public CascadingDropDownNameValue[] Getclasses(string knownCategoryValues, string category)
        {
            StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            if (!kv.ContainsKey("phylum"))
            {
                return null;
            }
            string phylum = kv["phylum"];
            List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
            foreach (var dr in Category.Instance.Getclasses(phylum))
            {
                values.Add(new CascadingDropDownNameValue(dr, dr));
            }
            return values.ToArray();
        }

        [WebMethod]
        public CascadingDropDownNameValue[] Getfamilies(string knownCategoryValues, string category)
        {
            StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            if (!kv.ContainsKey("classid"))
            {
                return null;
            }
            string classid = kv["classid"];
            List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
            foreach (var dr in Category.Instance.Getfamilies(classid))
            {
                values.Add(new CascadingDropDownNameValue(dr, dr));
            }
            return values.ToArray();
        }

        [WebMethod]
        public CascadingDropDownNameValue[] Getgenuses(string knownCategoryValues, string category)
        {
            StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            if (!kv.ContainsKey("family"))
            {
                return null;
            }
            string family = kv["family"];
            List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
            foreach (var dr in Category.Instance.Getgenuses(family))
            {
                values.Add(new CascadingDropDownNameValue(dr, dr));
            }
            return values.ToArray();
        }
        [WebMethod]
        [ScriptMethod]
        public string[] GetNames(string prefixText, int count) 
        {
            return Category.Instance.FindNames(prefixText, count);
        }
    }
}
